home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / _threading_local.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __all__ = [
  5.     'local']
  6.  
  7. class _localbase(object):
  8.     __slots__ = ('_local__key', '_local__args', '_local__lock')
  9.     
  10.     def __new__(cls, *args, **kw):
  11.         self = object.__new__(cls)
  12.         key = ('_local__key', 'thread.local.' + str(id(self)))
  13.         object.__setattr__(self, '_local__key', key)
  14.         object.__setattr__(self, '_local__args', (args, kw))
  15.         object.__setattr__(self, '_local__lock', RLock())
  16.         if (args or kw) and cls.__init__ is object.__init__:
  17.             raise TypeError('Initialization arguments are not supported')
  18.         
  19.         dict = object.__getattribute__(self, '__dict__')
  20.         currentThread().__dict__[key] = dict
  21.         return self
  22.  
  23.  
  24.  
  25. def _patch(self):
  26.     key = object.__getattribute__(self, '_local__key')
  27.     d = currentThread().__dict__.get(key)
  28.     if d is None:
  29.         d = { }
  30.         currentThread().__dict__[key] = d
  31.         object.__setattr__(self, '__dict__', d)
  32.         cls = type(self)
  33.         if cls.__init__ is not object.__init__:
  34.             (args, kw) = object.__getattribute__(self, '_local__args')
  35.             cls.__init__(self, *args, **kw)
  36.         
  37.     else:
  38.         object.__setattr__(self, '__dict__', d)
  39.  
  40.  
  41. class local(_localbase):
  42.     
  43.     def __getattribute__(self, name):
  44.         lock = object.__getattribute__(self, '_local__lock')
  45.         lock.acquire()
  46.         
  47.         try:
  48.             _patch(self)
  49.             return object.__getattribute__(self, name)
  50.         finally:
  51.             lock.release()
  52.  
  53.  
  54.     
  55.     def __setattr__(self, name, value):
  56.         lock = object.__getattribute__(self, '_local__lock')
  57.         lock.acquire()
  58.         
  59.         try:
  60.             _patch(self)
  61.             return object.__setattr__(self, name, value)
  62.         finally:
  63.             lock.release()
  64.  
  65.  
  66.     
  67.     def __delattr__(self, name):
  68.         lock = object.__getattribute__(self, '_local__lock')
  69.         lock.acquire()
  70.         
  71.         try:
  72.             _patch(self)
  73.             return object.__delattr__(self, name)
  74.         finally:
  75.             lock.release()
  76.  
  77.  
  78.     
  79.     def __del__(self):
  80.         import threading as threading
  81.         key = object.__getattribute__(self, '_local__key')
  82.         
  83.         try:
  84.             threads = list(threading.enumerate())
  85.         except:
  86.             return None
  87.  
  88.         for thread in threads:
  89.             
  90.             try:
  91.                 __dict__ = thread.__dict__
  92.             except AttributeError:
  93.                 continue
  94.  
  95.             if key in __dict__:
  96.                 
  97.                 try:
  98.                     del __dict__[key]
  99.                 except KeyError:
  100.                     pass
  101.                 except:
  102.                     None<EXCEPTION MATCH>KeyError
  103.                 
  104.  
  105.             None<EXCEPTION MATCH>KeyError
  106.         
  107.  
  108.  
  109. from threading import currentThread, RLock
  110.